/*
 -----------------------------------------------------------------------------
 This source file is part of FolderProtector
 Copyright (c) 2011, Vyacheslav Chigrin, folderprotector (at) gmail.com  All rights reserved.
 Send your commends
	 ---The BSD 3-Clause License---
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation and/or
  other materials provided with the distribution.
* Neither the name of the Folder Protector project nor the names of its contributors
  may be used to endorse or promote products derived from this software without specific
  prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -----------------------------------------------------------------------------
*/
#include "HideActionDlg.h"
#include "GuiConstants.h"

CHideActionDlg::CHideActionDlg( wxWindow* parent,const wxString& folderPath, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) 
    : wxDialog( parent, id, _(PROGRAM_NAME), pos, size, style )
    , m_FolderPath(folderPath)
{
    this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
    wxBoxSizer* bSizer2;
    bSizer2 = new wxBoxSizer( wxVERTICAL );
	
    wxStaticText* staticText2;
    staticText2 = new wxStaticText( this, wxID_ANY, _("Which action to take?"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
    staticText2->Wrap( -1 );
    bSizer2->Add( staticText2, 0, wxALL|wxEXPAND, 5 );
	
    m_radioBtnHideAll = new wxRadioButton( this, ID_RBTN_HIDE_ALL, _("Hide entire folder"), wxDefaultPosition, wxDefaultSize, 0 );
    bSizer2->Add( m_radioBtnHideAll, 0, wxALL, 5 );
	
    m_radioBtnHidePattern = new wxRadioButton( this, ID_RBTN_HIDE_PATTERN, _("Hide objects in folder by mask"), wxDefaultPosition, wxDefaultSize, 0 );
    bSizer2->Add( m_radioBtnHidePattern, 0, wxALL, 5 );
	
    wxBoxSizer* bSizer3;
    bSizer3 = new wxBoxSizer( wxHORIZONTAL );
	
    wxStaticText* staticText3;
    staticText3 = new wxStaticText( this, wxID_ANY, _("Objects pattern:"), wxDefaultPosition, wxDefaultSize, 0 );
    staticText3->Wrap( -1 );
    bSizer3->Add( staticText3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
    m_textCtrlPattern = new wxTextCtrl( this, ID_TEXT_PATTERN, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    bSizer3->Add( m_textCtrlPattern, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
    bSizer2->Add( bSizer3, 1, wxEXPAND, 5 );
	
    m_radioBtnHideFile = new wxRadioButton( this, ID_RBTN_HIDE_FILE, wxT("Hide specific file"), wxDefaultPosition, wxDefaultSize, 0 );
    bSizer2->Add( m_radioBtnHideFile, 0, wxALL, 5 );
	
    wxBoxSizer* bSizer4;
    bSizer4 = new wxBoxSizer( wxHORIZONTAL );
	
    staticText4 = new wxStaticText( this, wxID_ANY, _("File name:"), wxDefaultPosition, wxDefaultSize, 0 );
    staticText4->Wrap( -1 );
    bSizer4->Add( staticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
    m_staticFileName = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	m_staticFileName->Wrap( -1 );
	bSizer4->Add( m_staticFileName, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
	
	m_buttonBrowse = new wxButton( this, ID_BTN_BROWSE, _("Browse..."), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer4->Add( m_buttonBrowse, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );

	
    bSizer2->Add( bSizer4, 1, wxEXPAND, 5 );
	
    m_sdbSizer1 = new wxStdDialogButtonSizer();
    m_sdbSizer1OK = new wxButton( this, wxID_OK );
    m_sdbSizer1->AddButton( m_sdbSizer1OK );
    m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL );
    m_sdbSizer1->AddButton( m_sdbSizer1Cancel );
    m_sdbSizer1->Realize();
    bSizer2->Add( m_sdbSizer1, 1, wxEXPAND, 5 );
	
    this->SetSizer( bSizer2 );
    this->Layout();
	
    this->Centre( wxBOTH );
    m_radioBtnHideAll->SetValue(true);
    m_textCtrlPattern->SetValue(_T("*.*"));
}

CHideActionDlg::~CHideActionDlg()
{
}

BEGIN_EVENT_TABLE(CHideActionDlg, wxDialog)
   // EVT_UPDATE_UI(ID_FILE_PICKER, CHideActionDlg::OnUpdateFilePicker)
    EVT_UPDATE_UI(ID_TEXT_PATTERN, CHideActionDlg::OnUpdateTextPattern)
    EVT_UPDATE_UI(wxID_OK, CHideActionDlg::OnUpdateBtnOk)
    EVT_UPDATE_UI(ID_BTN_BROWSE,CHideActionDlg::OnUpdateBtnBrowse)
    EVT_BUTTON(ID_BTN_BROWSE,CHideActionDlg::OnBtnBrowse)
    EVT_BUTTON(wxID_OK,CHideActionDlg::OnOk)
END_EVENT_TABLE()

const wxString& CHideActionDlg::GetFinalPath()const
{
    return m_FinalPath;
}

void CHideActionDlg::OnUpdateTextPattern(wxUpdateUIEvent& evt)
{
    evt.Enable(m_radioBtnHidePattern->GetValue());
}

void CHideActionDlg::OnOk(wxCommandEvent& evt)
{
    m_FinalPath=_T("");
    if(m_radioBtnHideAll->GetValue())
    {
        m_FinalPath=m_FolderPath;
        if(m_FinalPath.GetChar(m_FinalPath.Len()-1)==_T('\\'))
            m_FinalPath=m_FinalPath.substr(0,m_FinalPath.Len()-1);
    }
    else if(m_radioBtnHideFile->GetValue())
    {
        m_FinalPath=m_FolderPath;
        if(m_FinalPath.GetChar(m_FinalPath.Len()-1)!=_T('\\'))
            m_FinalPath+=_T('\\');
        m_FinalPath+=m_staticFileName->GetLabel();
    }
    else if(m_radioBtnHidePattern->GetValue())
    {
        m_FinalPath=m_FolderPath;
        if(m_FinalPath.GetChar(m_FinalPath.Len()-1)!=_T('\\'))
            m_FinalPath+=_T('\\');
        m_FinalPath+=m_textCtrlPattern->GetValue();
    }
    EndDialog(wxID_OK);
}

void CHideActionDlg::OnUpdateBtnOk(wxUpdateUIEvent& evt)
{
    if(m_radioBtnHideAll->GetValue())
    {
        evt.Enable(true);
    }
    else if(m_radioBtnHideFile->GetValue())
    {
        evt.Enable(!m_staticFileName->GetLabel().IsEmpty());
    }
    else if(m_radioBtnHidePattern->GetValue())
    {
        evt.Enable(!m_textCtrlPattern->IsEmpty());
    }
}

void CHideActionDlg::OnUpdateBtnBrowse(wxUpdateUIEvent& evt)
{
    evt.Enable(m_radioBtnHideFile->GetValue());
}

void CHideActionDlg::OnBtnBrowse(wxCommandEvent& evt)
{
    wxFileDialog dlg(this);
    dlg.SetDirectory(m_FolderPath);
    if(dlg.ShowModal()!=wxID_OK)
        return;
    m_staticFileName->SetLabel(dlg.GetFilename());
}
